Skip to content

point empty ext_ref at a shared zero byte instead of its own member - #1240

Open
rajath201 wants to merge 1 commit into
msgpack:cpp_masterfrom
rajath201:ext-ref-empty-copy
Open

rajath201 wants to merge 1 commit into
msgpack:cpp_masterfrom
rajath201:ext-ref-empty-copy

Conversation

@rajath201

Copy link
Copy Markdown

An empty msgpack::type::ext_ref points m_ptr at its own m_size so that type() can skip a null check, but the implicit copy constructor and copy assignment copy that pointer as-is. Every copy of a default constructed ext_ref therefore keeps referring to the original object: push_back(ext_ref()), assignment from a temporary, or a boost::variant holding one is left with a dangling pointer once the source goes away, and type(), operator==, operator< and str() read freed stack or heap memory. The new case in security_fixes_cpp11.cpp shows type() returning whatever now occupies the dead source.

Point the empty state at a function-local static zero byte instead, so an ext_ref is a plain value that survives copies, type() is 0 and data() is a valid empty range; object<ext_ref> also stops publishing a pointer into the ext_ref itself. Doing it in the constructors keeps the accessors branch-free and avoids hand-written copy operations or caller-side lifetime rules. Targets cpp_master.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.41%. Comparing base (39cc081) to head (89b27bd).
⚠️ Report is 71 commits behind head on cpp_master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff               @@
##           cpp_master    #1240      +/-   ##
==============================================
- Coverage       85.36%   80.41%   -4.96%     
==============================================
  Files              80       80              
  Lines            5099     5862     +763     
  Branches          507      659     +152     
==============================================
+ Hits             4353     4714     +361     
- Misses            746     1148     +402     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants